package io.noties.markwon.base.html.tag

import android.text.style.*
import io.noties.markwon.base.MarkwonVisitor
import io.noties.markwon.base.SpannableBuilder
import io.noties.markwon.base.html.*

class UnderlineHandler : TagHandler() {
    override fun handle(
        visitor: MarkwonVisitor,
        renderer: MarkwonHtmlRenderer,
        tag: HtmlTag
    ) {

        // as parser doesn't treat U tag as an inline one,
        // thus doesn't allow children, we must visit them first
        if (tag.isBlock) {
            visitChildren(visitor, renderer, tag.asBlock)
        }
        SpannableBuilder.setSpans(
            visitor.builder(),
            UnderlineSpan(),
            tag.start(),
            tag.end()
        )
    }

    override fun supportedTags(): List<String> {
        return listOf("u", "ins")
    }
}